﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICeFramework.FindReplace;

namespace ICeFramework.Win.UI.Dialogs
{
    public partial class FindReplaceDialog : UserControl
    {
        private bool _defineOnly;
        public bool DefineOnly
        {
            get { return _defineOnly; }
            set 
            {
                _defineOnly = value;
                SetControlStatus();
            }
        }

        private IFindReplace _findReplace;
        public IFindReplace FindReplace
        {
            get { return _findReplace; }
            set { _findReplace = value; }
        }

        public FindReplaceDialog()
        {
            InitializeComponent();
            SetControlStatus();
            //(this.Parent as Form).FormClosed
        }

        public FindReplaceDialog(IFindReplace findReplace)
        {
            FindReplace = findReplace;
            InitializeComponent();
            SetControlStatus();
            //(this.Parent as Form).FormClosed
        }

        #region private void SetControlStatus()
        /// <summary>
        /// 
        /// </summary>
        private void SetControlStatus()
        {
            if (_findReplace == null)
            {
                return;
            }
            chkReplace.Checked = _findReplace.Options.ContextType == FindReplaceType.FindReplace;
            foreach (SearchScopeItem item in _findReplace.Options.ScopeList)
            {
                cbxScope.Items.Add(item.Name);
                cbxScope.CheckBoxItems[item.Name].Checked = item.Active;
            }
            rbNormal.Checked = _findReplace.Options.OperationType == FindReplaceOperationType.Normal;
            rbWildcards.Checked = _findReplace.Options.OperationType == FindReplaceOperationType.Wildcards;
            rbRegex.Checked = _findReplace.Options.OperationType == FindReplaceOperationType.Regex;
            chkMatchCase.Checked = _findReplace.Options.MatchCase;
            chkWholeWords.Checked = _findReplace.Options.MatchWholeWords;
            chkMatchPrefix.Checked = _findReplace.Options.MatchPrefix;
            chkMatchSuffix.Checked = _findReplace.Options.MatchSuffix;
            btnFindNext.Visible = !_defineOnly;
            btnReplace.Visible = !_defineOnly;
            btnReplaceAll.Visible = !_defineOnly;
            btnSave.Visible = _defineOnly;
        }
        #endregion
    }
}
